package gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

/**
 * @author dotekien
 *         Date: Mar 29, 2006
 *         Time: 12:21:01 PM
 */
public class OpenHtmlPage implements ActionListener {
    JFrame frame;
    String fileName;
    Dimension dim;
    String title;

    public OpenHtmlPage(JFrame frame, String title, String fileName, Dimension dim) {
        this.frame = frame;
        this.fileName = fileName;
        this.dim = dim;
        this.title = title;
    }

    public void actionPerformed(ActionEvent e) {
        setPage();
    }

    private void setPage() {
        JDialog dialog = new JDialog(frame, title);
        dialog.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        JPanel contentPane = new JPanel(new BorderLayout());

        java.net.URL helpURL = getClass().getResource(fileName);
        assert helpURL != null : "Failed to find URL " + fileName;
        JEditorPane htmlPane = new JEditorPane();
        try {
            htmlPane.setPage(helpURL);
            htmlPane.setEditable(false);

            JScrollPane scrollPane = new JScrollPane(htmlPane);
            contentPane.add(scrollPane, BorderLayout.CENTER);
            dialog.setSize(dim);

        } catch (IOException exception) {
            System.err.println("Cannnot get Page " + fileName);
            exception.printStackTrace();
        }

        contentPane.setOpaque(true);
        dialog.setContentPane(contentPane);

        //Show it.
        dialog.setLocationRelativeTo(frame);
        dialog.setVisible(true);
    }

// --Commented out by Inspection START (4/30/07 5:22 PM):
//    public void mouseClicked(MouseEvent e) {
//        setPage();
//    }
// --Commented out by Inspection STOP (4/30/07 5:22 PM)
}

